/**
* Copyright 2023 PYSTOR DBS, Nanjing Pengyun Network Technology Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ 

package py.dd;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import py.app.thrift.ThriftAppEngine;
import py.app.thrift.ThriftProcessorFactory;
import py.dd.utils.DdUtils;
import py.dd.worker.LogCollector;

/**
 * xx.
 */
public class DeploymentDaemonAppEngine extends ThriftAppEngine {

  private static Logger logger = LoggerFactory.getLogger(DeploymentDaemonAppEngine.class);

  private Bootstrap bootstrap;
  private LogCollector logCollector;
  private boolean ftpSwitch;

  public DeploymentDaemonAppEngine(ThriftProcessorFactory processorFactory) {
    super(processorFactory);
  }

  public void setBootstrap(Bootstrap bootstrap) {
    this.bootstrap = bootstrap;
  }

  /**
   * xx.
   */
  public void start() throws Exception {
    super.start();

    logger.info("Init dd utils ...");
    DdUtils.init();

    if (!ftpSwitch) {
      logger.warn("ftp switch:{}, do not start ftp thread", ftpSwitch);
      return;
    }

    try {
      logCollector.start();
    } catch (Exception e) {
      logger.error("Caught an exception when start log collector", e);
      //throw e;
    }
  }


  public LogCollector getLogCollector() {
    return logCollector;
  }

  public void setLogCollector(LogCollector logCollector) {
    this.logCollector = logCollector;
  }

  public boolean isFtpSwitch() {
    return ftpSwitch;
  }

  public void setFtpSwitch(boolean ftpSwitch) {
    this.ftpSwitch = ftpSwitch;
  }

}
